<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/5/18
 * Time: 10:12
 */

namespace App\Http\Controllers\Drivers\V2\Car;


use App\Http\Controllers\Controller;
use App\Services\CarService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class CarController extends Controller
{
    /**
     * 车辆列表
     */
    public function lists(Request $request, CarService $service)
    {
        return $this->sendJson($service->getList(Auth::user()));
    }

    /**
     * 编辑
     */
    public function edits(Request $request, CarService $service)
    {
        $car_id = (int)$request->post('car_id', ''); //车辆ID
        if (empty($car_id)) return_bobc('车辆ID必传');
        $service = $service->car_edits($car_id);
        return $this->sendJson($service);
    }

    /**
     * @param Request $request
     * @param CarService $service
     * 出车状态
     */
    public function car_status(Request $request, CarService $service)
    {
        $car_id = (int)$request->post('car_id');
        $status = $service->car_status($car_id);
        if ($status) {
            return $this->sendJson($status);
        }
        return $this->sendError('error');
    }

    /**
     * @param Request $request
     * @param CarService $service
     * @return CarController|\Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\BobException
     * 状态修改
     */
    public function car_edit_status(Request $request, CarService $service)
    {
        $car_id = (int)$request->post('car_id');
        $type = (string)$request->post('type');
        $user = Auth::user();
        $status = $service->car_edit_statussss($user, $car_id, $type);
        return $this->sendJson($status);

    }

    /**
     * 转让 主司机  删除司机
     */
    public function drivers_car_int(Request $request, CarService $service)
    {
        $car_id = (int)$request->post('car_id', ''); //车辆ID
        $drivers_id = (int)$request->post('drivers_id', ''); //车辆ID
        $type = (string)$request->post('type', ''); //车辆ID
        if ($service->drivers_car_int($car_id, $drivers_id, $type)) {
            return $this->sendSuccess('OK');
        };
        return $this->sendError('error');
    }

    /**
     * 查询司机
     */
    public function add_drivers(Request $request, CarService $service)
    {
        $phone = (string)$request->post('phone', ''); //电话
        if (empty($phone))
            return $this->sendError('请输入手机号码');
        if ($info = $service->drivers($phone)) {
            return $this->sendJson($info);
        }
        return $this->sendError('该手机尚未注册');
    }
}